define([
	'vue',
	'config',
	'common',
	'../model/upLoadList',
	'../model/downLoadList',
	'moment',
	'vue-lazyload'
	],function(Vue,config,utils,upLoadList,downLoadList,moment,VueLazyload){
	'use strict';

	Vue.use(VueLazyload, {
	  preLoad: 1.3,
	  loading: '../../../image/loadingUP.gif',
	  attempt: 6
	})

	var loreView=new Vue({
		el:'#app',
		data:{
			items:'',
			page: 1,
			totalPage:0,
			pageSize:'',
			loreDetail:'',

			detile:'',
			aboutItems:'',
			aboutText:'',
			culture:'',
		},
		filters:{
			moment:function(date){
				var Date = moment(date*1000).format('YYYY-MM-DD');
				return Date;
			},
			amoment:function(date){
				var Date = moment(date*1000).format('YYYY-MM-DD HH:mm:ss');
				return Date;
			}
		},
		watch:{
			items: function(to,from){
				if(to.length == 0 && this.items !== ""){
					$('#noData').show();
					$('.bottomCopy').hide();
				}else{
					$('#noData').hide();
					$('.bottomCopy').show();
				}
			},
		},
		created:function(){
			utils.userToken();

			var _this=this;
			_this.pageSize = 20;
			if (window.location.href.match("lore.html")) {
                //_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/219), 10);
                upLoadList.ajax(utils.getWebUrl('artic/list'),{
                	article_type_name: '讲师风采',
					pageSize: _this.pageSize,
					page: _this.page
                },function(res){
                	_this.items = res.data.list;
					_this.totalPage = res.data.totalPage;
                })

            }else if(window.location.href.match("news.html")){
            	//_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/104), 10);
            	upLoadList.ajax(utils.getWebUrl('artic/list'),{
                	article_type_name: '行业资讯',
					pageSize: _this.pageSize,
					page: _this.page
                },function(res){
                	_this.items = res.data.list;
					_this.totalPage = res.data.totalPage;
                })

            }else if(window.location.href.match("loreDetail.html")||window.location.href.match("newsDetail.html")){
            	var id = utils.getQueryVariable('id');
				utils.ajax(utils.getWebUrl('artic/get'),{
					id: id
				},'POST',function(res){
					_this.loreDetail = res.data;
				})
            }else if(window.location.href.match("about.html")){

            	utils.ajax(utils.getWebUrl('artic/list'),{
					article_type_name: 'E享文化'
				},'POST',function(res){
					_this.aboutItems = res.data.list;
					if(_this.aboutItems.length == 0){
						$('#noData').show();
					}
				},function(){
					$('.DataLoading').show();
				},function(){
					$('.DataLoading').hide();
				})

            }else if(window.location.href.match("aboutText.html")||window.location.href.match("culture.html")){
            	var id = utils.getQueryVariable('id');
				utils.ajax(utils.getWebUrl('artic/get'),{
					id: id
				},'POST',function(res){
					_this.aboutText = res.data;
				},function(){
					$('.DataLoading').show();
				},function(){
					$('.DataLoading').hide();
				})
            }
		},
		directives: {
		  scroll: {
		    inserted: function (el, binding){
		      var binding =binding;
		      window.addEventListener('scroll',function() {
		       		var fnc = binding.value;   
   					fnc();
		      })
		    }
		  }
		},
		methods:{
			toRefresh: function(){
				window.location.reload();
			},
			toIndex: function(){
				var userTypeId =utils.getData('userTypeId');
				if(userTypeId == 4){
					window.location.href='userInfo.html';
				}else{
					window.location.href='shopInfo.html';
				}
			},
			loadMore:function(event){
				var _this = this;
				if ((parseInt(Math.ceil($(document).scrollTop() + window.innerHeight)) >= parseInt(Math.ceil($(document).height()))) &&_this.page<_this.totalPage) {
					_this.page = _this.page+1;
					var data = {
						article_type_id: 1,
						pageSize: _this.pageSize,
						page: _this.page
					}
					utils.ajax(utils.getWebUrl('artic/list'),data,'POST',function(res){
						//console.log(res)
						_this.items = _this.items.concat(res.data.list);
					},function(){
						$('#pullDown3').show();
					},function(){
						$('#pullDown3').hide();
					})
		        }
			},
			Start:function(event){

				var touch = event.targetTouches[0];
				this.start = touch.pageY;

			},

			Move:function(event){
				var touch = event.targetTouches[0];
				this.end = (this.start - touch.pageY);
				var slideDown1 = $('#pullDown1');
				//下滑才执行操作 
                if(this.end < 0){
                	
                	slideDown1.text('下拉刷新  ↓');
	        		slideDown1.show();
	        		slideDown1[0].style.height =  (parseInt("0px")-this.end) + "px";
	        		if(this.end < -48){
	        			/*slideDown1.hide(); 
	        			downLoadList.slideDownStep1(this.end);*/
	        			slideDown1.text('松手开始更新  ↑')
	        		}
                }else{
                	slideDown1.hide();
                }
			},

			End:function(event){
				var _this = this;
				var slideDown1 = $('#pullDown1');
				if(this.end >0){  
					slideDown1.hide();
	            }else{ 

	                if(this.end < -48 && document.body.scrollTop == 0){
	                	var slideDown1 = $('#pullDown1');
	                	var slideDown2 = $('#pullDown2');

						slideDown1.hide();
				        slideDown2.show();

	                	downLoadList.slideDownStep2(); 
		                //刷新成功则 
		                //请求数据
		                _this.page = 1;
		                var article_type_name;
		                if(window.location.href.match("lore.html")){
		                	article_type_name = '讲师风采';
		                	//_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/219), 10);
		                }else{
		                	article_type_name = '行业资讯';
		                	//_this.pageSize = parseInt(Math.ceil(($('body').height()-$('.headTitle').height())/104), 10);
		                }

		                utils.ajax(utils.getWebUrl('artic/list'),{
		                	article_type_name: article_type_name,
							pageSize: _this.pageSize,
							page: _this.page
		                },'POST',function(res){
		                		_this.items = res.data.list;
								_this.totalPage = res.data.totalPage;
		                },null,function(){
							downLoadList.slideDownStep3();
						})
		                
	                }else{
	                	var slideDown1 = $('#pullDown1');
		        		slideDown1.hide();
	                }
	            }
			},
			toDetile:function(event){
				var $target = $(event.currentTarget);
				var id = $target.data('id');
				window.location.href="loreDetail.html?id="+id;
			},
			toAboutDetile:function(event){
				var $target = $(event.currentTarget);
				var id = $target.data('id');
				var index = $target.data('index');
				window.location.href="aboutText.html?id="+id;
				/*if(index == 0){
					window.location.href="aboutText.html?id="+id;
				}else if(index == 1){
					window.location.href="culture.html?id="+id;
				}*/
			},
			tonewsDetail:function(event){
				var $target = $(event.currentTarget);
				var id = $target.data('id');
				window.location.href="newsDetail.html?id="+id;
			}
		}
	})

	return loreView;
});